home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 12380 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.4 KB  |  105 lines

  1. Path: yama.mcc.ac.uk!liv!strath-cs!st-and!pf2
  2. From: pf2@st-andrews.ac.uk (Peter Foldiak)
  3. Newsgroups: comp.sys.sgi.bugs,comp.sys.sgi.apps,comp.sys.sgi.misc,comp.lang.c++
  4. Subject: C++ template "already defined" error - any ideas?
  5. Date: 19 Mar 1996 19:43:35 GMT
  6. Organization: University Of St. Andrews, Fife, UK.
  7. Message-ID: <4in2p7$27b@calvin.st-and.ac.uk>
  8. NNTP-Posting-Host: psych.st-and.ac.uk
  9. NNTP-Posting-User: pf2
  10.  
  11.  
  12. I would like to ask for some help with the following problem that seems
  13. to be specific to the SGI CC compiler (Delta/C++), (as Turbo C does not
  14. seem to give similar error messages.)
  15. I tried to simplify the files as much as possible.
  16. If you have any ideas what the problem may be please email me
  17. directly or send a copy of your followup by email
  18. (mailto:pf2@st-andrews.ac.uk)  Thanks!
  19.  
  20. When I try to compile the files below on a SG Indy (Irix 5.3) I get the
  21. following error:
  22.  
  23. ----
  24. % CC main.c list.c
  25. main.c:
  26. "list.h", line 1: error(3328): class template "list" has already been
  27. defined
  28.   template<class T> class list {
  29.                           ^
  30. 1 error detected in the compilation of "main.c".
  31. list.c:
  32. %
  33. ----
  34. (By the way, how do I find out what error(3328) is in more detail?)
  35.  
  36. If I concatenate list.c and main.c into a file called listmain.c,
  37. and compile with
  38. % CC listmain.c
  39. %
  40. the error message disapprears! So I guess it has something to do
  41. with the bits being in separate files.
  42. Also, if the files contain no templates there is no error.
  43. Could anyone please help? Any ideas?
  44. Is there something special with including headrers when I use templates?
  45. Thanks!
  46.  
  47. Peter
  48. -
  49.  
  50. ===========================================
  51. The files that won't compile:
  52.  
  53. list.h:
  54. -------
  55. template<class T> class list {
  56.         T x;
  57.         list *next;
  58. public:
  59.         list<T>::list();
  60. };
  61.  
  62. list.c:
  63. -------
  64. #include <stdio.h>
  65. #include "list.h"
  66. template<class T> list<T>::list()
  67. {
  68.         next = NULL;
  69. }
  70.  
  71. main.c:
  72. -------
  73. #include "list.h"
  74. int main()
  75. {
  76.         list<int> q;
  77.         return 0;
  78. }
  79.  
  80.  
  81. =======================================
  82. This file compiles without error:
  83. listmain.c:
  84. -----------
  85. #include <stdio.h>
  86. #include "list.h"
  87.  
  88. template<class T> list<T>::list()
  89. {
  90.         next = NULL;
  91. }
  92.  
  93. int main()
  94. {
  95.         list<int> q;
  96.         return 0;
  97. }
  98.  
  99. -- 
  100. Peter Foldiak                     http://psych.st-and.ac.uk:8080/~pf2
  101. Psychological Laboratory          phone: +44 1334 462087
  102. University of St Andrews          fax:   +44 1334 463042
  103. St Andrews KY16 9JU, U.K.         e-mail: Peter.Foldiak@st-and.ac.uk
  104.  
  105.